<?php
/**
 * Yii view _form_service
 *
 * @author nguyenmanhluu
 * @since Jul 26, 2013 - 4:43:42 PM
 */
?>
<?php $typeText = $model->type == Service::TYPE_ROOM ? 'Class' : 'Service' ?>
<div class="box span12">
    <div class="box-header">
        <h2>
            <i class="icon-plus"></i>
            <?php echo $model->isNewRecord ? 'Add' : 'Edit' ?>
            <?php echo $typeText ?>
        </h2>
        <div class="box-icon">
            <a href="#" onclick="return closeService();">
                <i class="icon-remove"></i>
            </a>
        </div>
    </div>
    <div class="box-content">
        <?php
        $form_id  = strtolower($typeText) . '-form';
        $form_id .= $model->isNewRecord ? '-add' : '-edit';

        $form = $this->beginWidget('CActiveForm', array(
            'id'                     => $form_id,
//            'enableAjaxValidation' => true,
            'enableClientValidation' => true,
            'htmlOptions'            => array(
                'class'   => 'form-horizontal',
                'enctype' => 'multipart/form-data',
            ),
            'focus'                  => array($model, 's_name'),
            'clientOptions'          => array(
                'validateOnSubmit' => true,
            ),
        ));
        ?>
        <?php echo CHtml::errorSummary($model); ?>
        <fieldset>            

            <?php if (Yii::app()->controller->isAdmin): ?>                
                <div class="control-group">
                    <?php echo $form->label($model, 'author_id', array('class' => 'control-label')) ?>
                    <div class ="controls">                                                        
                        <?php echo $form->dropDownList($model, 'author_id', Users::getAllBussiness()); ?>                   
                        <font color="red"><?php echo $form->error($model, 'author_id'); ?></font>                   
                    </div>
                </div>            
            <?php endif; ?>
            <?php
            /**
             * neu la admin thi load biz
             * neu la biz thi load toan bo staff 
             */
            ?>

            <?php if (Yii::app()->controller->isBussiness): ?>
                <div class="control-group">
                    <div class ="controls">
                        <?php
                        $staffs = Users::getAllStaffByBusiness(Yii::app()->user->getId(), FALSE);
                        if ($staffs != NULL)
                        {
                            foreach ($staffs as $k => $st)
                            {
                                echo CHtml::checkBoxList('SaffID[]', false, array($k => $st)) . '<br>';
                            }
                        }
                        ?>
                    </div>   
                </div>
            <?php endif; ?>

            <div class="control-group">
                <?php echo $form->label($model, 'category_id', array('class' => 'control-label')) ?>
                <div class ="controls">                

                    <?php $data = CHtml::listData(Category::GetAllCategory(), 'id', 'name_cat', 'group'); ?>
                    <?php echo $form->dropDownList($model, 'category_id', $data); ?>

                    <font color="red"><?php echo $form->error($model, 'category_id'); ?></font>

                </div>
            </div>
            <div class="control-group">
                <?php echo $form->labelEx($model, 's_name', array('class' => 'control-label')); ?>
                <div class ="controls">
                    <?php
                    echo $form->textField($model, 's_name', array(
                        'placeholder' => $model->getAttributeLabel('s_name'),
                        'class'       => 'input-file uniform_on input-reset'
                    ));
                    ?>
                    <font color="red"><?php echo $form->error($model, 's_name'); ?></font>
                </div>
            </div>
            <div class="control-group">
                <?php echo $form->label($model, 'duration', array('class' => 'control-label')) ?>
                <div class ="controls">                
                    <?php echo $form->dropDownList($model, 'duration', Service::getDurationArray()); ?>
                    <font color="red"> <?php echo $form->error($model, 'duration'); ?> </font>
                </div>
                <font color="red"> <?php echo $form->error($model, 'duration'); ?> </font>
            </div>
            <div class="control-group">
                <?php echo $form->labelEx($model, 'price', array('class' => 'control-label')); ?>
                <div class ="controls">
                    $ <?php
                    echo $form->textField($model, 'price', array(
                        'placeholder' => $model->getAttributeLabel('price'),
                        'class'       => 'input-file uniform_on input-reset span6'
                    ));
                    ?>
                    <font color="red"><?php echo $form->error($model, 'price'); ?></font>
                </div>
            </div>    
            <div class="control-group">
                <?php echo $form->label($model, 'recover', array('class' => 'control-label')) ?>
                <div class ="controls">                
                    <?php
                    echo $form->dropDownList($model, 'recover', Service::getRecoverArray());
                    ?>
                    <font color="red"> <?php echo $form->error($model, 'duration'); ?> </font>
                </div>
                <font color="red"> <?php echo $form->error($model, 'duration'); ?> </font>
            </div>
            <div class="control-group">
                <?php echo $form->labelEx($model, 'description', array('class' => 'control-label')); ?>
                <div class ="controls">
                    <?php
                    echo $form->textArea($model, 'description', array(
                        'style'       => 'height:70px',
                        'placeholder' => $model->getAttributeLabel('description'),))
                    ?>
                    <font color="red"><?php echo $form->error($model, 'description'); ?></font>
                </div>
            </div>
            <div class="control-group">
                <?php echo $form->labelEx($model, 'book_online', array('class' => 'control-label')); ?>
                <div class ="controls">
                    <?php
                    echo $form->checkBox($model, 'book_online', array(
                        'class'       => 'input-file uniform_on input-reset',
                        'placeholder' => $model->getAttributeLabel('book_online'),))
                    ?>
                    Service can book online
                    <font color="red"><?php echo $form->error($model, 'book_online'); ?></font>
                </div>
            </div>
            <div class="control-group">
                <?php echo $form->labelEx($model, 'images', array('class' => 'control-label')); ?>
                <div class ="controls">
                    <div class="user_photo">
                        <?php if ($model->sImages): ?>
                            <?php foreach ($model->sImages as $img): ?>
                                <div class="row-fluid box">
                                    <div class="span6">                                        
                                        <img src="<?php echo $img->publicImage ?>" alt="User photo">
                                    </div>
                                    <div class="span6">
                                        <p>
                                            <?php
                                            echo $form->radioButton($model, 'images', array(
                                                'value'        => $img->id,
                                                'uncheckValue' => null
                                            ));
                                            ?>
                                            Set default
                                        </p>
                                        <p>

                                            <input type="checkbox" name="delServiceImage[]" 
                                                   value="<?php echo $img->id ?>"/>
                                            Delete
                                        </p>
                                    </div>
                                    <div class="clear"></div>                                    
                                </div>
                            <?php endforeach; ?>
                        <?php else: ?>
                            <img src="<?php echo $model->publicImage ?>" alt="User photo">
                        <?php endif; ?>
                    </div>                                
                    <input type="file" name="file[]" multiple />
                    <font color="red"><?php echo $form->error($model, 'images'); ?></font>
                </div>
            </div>

            <div class="control-group">       
                <div class ="controls">
                    <input class="btn btn-primary" type="submit" value="Save <?php echo $typeText ?>" />
                    <a class="btn btn-inverse close_service" href="<?php echo Yii::app()->createUrl('service/index') ?>" >
                        <i class=""></i>Close
                    </a>
                </div>
            </div>
        </fieldset>
        <?php $this->endWidget(); ?>
    </div>
</div>